Attribute VB_Name = "cmnHgCmd"
'------------------- Copy & paste from here to the cmnRbnOnAct module of add-in file --------------------
'
' Copyright (C) 2012 Ken Majima <majimaji12@gmail.com>
'     All rights reserved.
'     This is free software with ABSOLUTELY NO WARRANTY.
'
' You can redistribute it and/or modify it under the terms of
' the GNU General Public License version 2.

Option Explicit

' Strings for Execute Mercurial Command
Private Const g_HgExec      As String = "hg.exe"
Private Const g_ThgExec      As String = "thg.exe"
Private Const g_ThgwExec      As String = "thgw.exe"

' Contents class hide Workbook, Documents and Presentations.
Dim mContents As New Contents

' :Function:     Execute TortoiseHg shell Command
' :Return value: Always return True
' :Discription:  "PrmtrSource" is a file name or file path
Function ExecHgCmd(ByVal HgExe As String, _
                   ByVal HgCmd As String, _
                   ByVal ContFilePath As String, _
                   ByVal PrmtrSource As String, _
                   Optional MesDisc As String) As Boolean
  ' TortoiseHg modules path
  Dim HgPath  As String
  
  Const HKEY_LOCAL_MACHINE = &H80000002
  HgPath = ReadRegStr(HKEY_LOCAL_MACHINE, "SOFTWARE\TortoiseHg", "", 64)
  
  If Len(HgPath) = 0 Then
    MsgBox "Failed to read TortoiseHg path from registory."
  End If


  ' WScript.Shell Object
  Dim WsShellObj    As Object
 
  Set WsShellObj = CreateObject("WScript.Shell")
  If WsShellObj Is Nothing Then
    MsgBox "Failed to CreateObject - WScript.Shell."
    Exit Function
  End If

 
  ' Hg Command Parameter
  Dim HgCmdParam  As String
  
  If Len(PrmtrSource) = 0 Then
    HgCmdParam = ""
  Else
    If Len(MesDisc) = 0 Then
      HgCmdParam = """" & PrmtrSource & """"
    Else
      HgCmdParam = """" & PrmtrSource & """" & MesDisc & ""
    End If
  End If

 
  Dim ECmd As String
  ECmd = HgExe & " " & HgCmd & " " & HgCmdParam

  'change current directory for run merucurial modules
  WsShellObj.CurrentDirectory = ContFilePath
  
  '----------------------------------
  'Execute Command with cmd.exe
  'and get standard output
  '----------------------------------
  'Dim WExec As Object
  'Dim Cmd As String
  'Cmd = ECmd
  '
  'Set WExec = WsShellObj.Exec("%ComSpec% /c " & ECmd)
  'Do While WExec.Status = 0
  '  DoEvents
  'Loop
  
  'Dim Result As String
  'Result = WExec.StdOut.ReadAll
  'MsgBox Result
  '
  'Set WExec = Nothing
  '----------------------------------
  '
  'Execute Command
  '----------------------------------
  Dim Ret As Integer
  Ret = WsShellObj.Run(ECmd, vbHide, True)
  
  '----------------------------------
  Set WsShellObj = Nothing
  
  If Ret > 1 Then
    MsgBox "Failed to ExecHgCmd."
  End If
  
  'MsgBox Ret & ", " & Err.Number & ", " & Err.Description
  ' in this way, commands always return 0 even if they fail.
  ' So, this function returns True always.
  
  ExecHgCmd = True
  
End Function


' :Function:     Execute TortoiseHg WorkBench
' :Return value: Always return True
Function ExecThgWB(ByVal ActCont As ActiveContent) As Boolean
  ' TortoiseHg modules path
  Dim HgPath  As String
  
  Const HKEY_LOCAL_MACHINE = &H80000002
  HgPath = ReadRegStr(HKEY_LOCAL_MACHINE, "SOFTWARE\TortoiseHg", "", 64)
  
  If Len(HgPath) = 0 Then
    MsgBox "Failed to read TortoiseHg path from registory."
  End If


  ' WScript.Shell Object
  Dim WsShellObj    As Object
 
  Set WsShellObj = CreateObject("WScript.Shell")
  If WsShellObj Is Nothing Then
    MsgBox "Failed to CreateObject - WScript.Shell."
    Exit Function
  End If

  Dim ECmd As String
  ECmd = g_ThgwExec

  'change current directory for run merucurial modules
  WsShellObj.CurrentDirectory = ActCont.GetFullPath()
  
  '----------------------------------
  '
  'Execute Command
  '----------------------------------
  Dim Ret           As Integer
  Ret = WsShellObj.Run(ECmd, , True)
  
  '----------------------------------
  Set WsShellObj = Nothing
  
  If Ret <> 0 Then
    MsgBox "Failed to ExecHgCmd."
  End If
  
  'MsgBox Ret & ", " & Err.Number & ", " & Err.Description
  ' in this way, commands always return 0 even if they fail.
  ' So, this function returns True always.
  
  ExecThgWB = True
  
End Function

' Reads a REG_SZ value from the local computer's registry using WMI.
' Parameters:
' RootKey - The registry hive (see http://msdn.microsoft.com/en-us/library/aa390788(VS.85).aspx for a list of possible values).
' Key - The key that contains the desired value.
' Value - The value that you want to get.
' RegType - The registry bitness: 32 or 64.
'
Function ReadRegStr(RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams

Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType

Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

Set oInParams = oReg.Methods_("GetStringValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value

Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)

ReadRegStr = oOutParams.sValue
End Function


' :Function: Update
' :Discription: HgUpdate doesnt work yet!
Sub HgUpdate()
  ' Message
  Dim msgErrMod As String
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent
  ' Ask user to abort update procedure
  Dim ansAskAbort As Integer
  ' True = Dispaly alerts on closing file
  Dim bAlertsOnClosing As Boolean

  ' Initialize flags
  bAlertsOnClosing = True

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFileUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  If ActiveContent.IsSaved = False Then
  ' Active content is modified but not saved yet.
    msgErrMod = _
    AddActiveContentNameToMsg(gmsgUpdateAskActiveContentMod, gmsgFileNameCap, _
                              True, ActiveContent)
    ansAskAbort = MsgBox(msgErrMod, vbYesNo)
    If ansAskAbort = vbYes Then
      Exit Sub
    Else
    ' User selected discard the changes of the data file.
    ' So, the file is closed without any warning messages.
      bAlertsOnClosing = False
    End If
  End If

  ActiveContent.StoreCurCursorPos
  ActiveContent.CloseFile bAlertsOnClosing

  ExecHgCmd g_ThgExec, "update", ActiveContent.GetFullPath, ActiveContent.GetFullName
  
  ActiveContent.ReOpenFile
  ActiveContent.JumpToStoredPos
End Sub

' :Function: Revert
Sub HgRevert()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod As String
  ' Return value of message box
  Dim ansSaveMod As Integer
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent
  ' True = Dispaly alerts on closing file
  Dim bAlertsOnClosing As Boolean
  ' True = Close and reopen file
  Dim bCloseReopen As Boolean

  ' Initialize flags
  bAlertsOnClosing = True
  ansSaveMod = vbYes

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If
  
  If ActiveContent.IsFileReadOnly Then
    msgErrReadOnly = _
    AddActiveContentNameToMsg(gmsgFileReadOnly, _
                                gmsgFileNameCap, True, ActiveContent)
    MsgBox msgErrReadOnly
    Exit Sub
  End If
  
  'Confitm revert
  Dim msgDoRevert As String
  msgDoRevert = _
    AddActiveContentNameToMsg(gmsgReverAsk, gmsgFileNameCap, True, ActiveContent)
  
  Dim ansDoRevert As Integer
  ansDoRevert = MsgBox(msgDoRevert, vbYesNo)

  If ansDoRevert = vbNo Then
    Exit Sub
  End If

  'save
  If ActiveContent.IsSaved = False Then
    If ActiveContent.SaveFile(True) = False Then
      Exit Sub
    End If
  End If
  

  ActiveContent.StoreCurCursorPos
  ActiveContent.CloseFile bAlertsOnClosing

  ExecHgCmd g_HgExec, "revert", ActiveContent.GetFullPath, ActiveContent.GetFullName
   
  ActiveContent.ReOpenFile
  ActiveContent.JumpToStoredPos
  
End Sub

Sub HgQuickCommit()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod As String
  ' Return value of message box
  Dim ansSaveMod As Integer
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent
  ' True = Dispaly alerts on closing file
  Dim bAlertsOnClosing As Boolean
  ' True = Close and reopen file
  Dim bCloseReopen As Boolean

  ' Initialize flags
  bAlertsOnClosing = True
  ansSaveMod = vbYes

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If
  
  bCloseReopen = NeedsCloseAndReopenFileInCommit(ActiveContent.GetFullName)

  If ActiveContent.IsSaved = False Then
  ' Active content is modified but not saved yet.
    ' Test the active content file attributes
    If ActiveContent.IsFileReadOnly Then
      msgErrReadOnly = _
      AddActiveContentNameToMsg(gmsgCommitErrActiveContentFileReadOnly, _
                                gmsgFileNameCap, True, ActiveContent)
      MsgBox msgErrReadOnly
      Exit Sub
    End If

    If GetDispAskSaveModMsg(True) = gCfgOn Then
      If bCloseReopen Then
        msgAskSaveMod = _
        AddActiveContentNameToMsg(gmsgCommitAskSaveModCloseReopen, gmsgFileNameCap, _
                                  True, ActiveContent)
      Else
        msgAskSaveMod = _
        AddActiveContentNameToMsg(gmsgCommitAskSaveMod, gmsgFileNameCap, _
                                  True, ActiveContent)
      End If
      
      ansSaveMod = MsgBox(msgAskSaveMod, vbYesNoCancel)
      If ansSaveMod = vbYes Then
        If ActiveContent.SaveFile(True) = False Then
          Exit Sub
        End If
      ElseIf ansSaveMod = vbCancel Then
        Exit Sub
      End If
    Else
      If ActiveContent.SaveFile(False) = False Then
        Exit Sub
      End If
    End If
  End If

  If bCloseReopen Then
    
    If ansSaveMod = vbNo Then
    ' User selected not to save the file.
    ' So, the file is closed without any warning messages.
      bAlertsOnClosing = False
    Else
      bAlertsOnClosing = True
    End If
    
    ActiveContent.StoreCurCursorPos
    ActiveContent.CloseFile bAlertsOnClosing

    ExecHgCmd g_HgExec, "commit", ActiveContent.GetFullPath, ActiveContent.GetFullName, " -m quick-saved "

    ActiveContent.ReOpenFile
    ActiveContent.JumpToStoredPos
  Else
    ExecHgCmd g_HgExec, "commit", ActiveContent.GetFullPath, ActiveContent.GetFullName, " -m quick-saved "
  End If
End Sub

' :Function: Commit
Sub HgCommit()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod As String
  ' Return value of message box
  Dim ansSaveMod As Integer
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent
  ' True = Dispaly alerts on closing file
  Dim bAlertsOnClosing As Boolean
  ' True = Close and reopen file
  Dim bCloseReopen As Boolean

  ' Initialize flags
  bAlertsOnClosing = True
  ansSaveMod = vbYes

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If
  
  bCloseReopen = NeedsCloseAndReopenFileInCommit(ActiveContent.GetFullName)

  If ActiveContent.IsSaved = False Then
  ' Active content is modified but not saved yet.
    ' Test the active content file attributes
    If ActiveContent.IsFileReadOnly Then
      msgErrReadOnly = _
      AddActiveContentNameToMsg(gmsgCommitErrActiveContentFileReadOnly, _
                                gmsgFileNameCap, True, ActiveContent)
      MsgBox msgErrReadOnly
      Exit Sub
    End If

    If GetDispAskSaveModMsg(True) = gCfgOn Then
      If bCloseReopen Then
        msgAskSaveMod = _
        AddActiveContentNameToMsg(gmsgCommitAskSaveModCloseReopen, gmsgFileNameCap, _
                                  True, ActiveContent)
      Else
        msgAskSaveMod = _
        AddActiveContentNameToMsg(gmsgCommitAskSaveMod, gmsgFileNameCap, _
                                  True, ActiveContent)
      End If
      
      ansSaveMod = MsgBox(msgAskSaveMod, vbYesNoCancel)
      If ansSaveMod = vbYes Then
        If ActiveContent.SaveFile(True) = False Then
          Exit Sub
        End If
      ElseIf ansSaveMod = vbCancel Then
        Exit Sub
      End If
    Else
      If ActiveContent.SaveFile(False) = False Then
        Exit Sub
      End If
    End If
  End If

  If bCloseReopen Then
    
    If ansSaveMod = vbNo Then
    ' User selected not to save the file.
    ' So, the file is closed without any warning messages.
      bAlertsOnClosing = False
    Else
      bAlertsOnClosing = True
    End If
    
    ActiveContent.StoreCurCursorPos
    ActiveContent.CloseFile bAlertsOnClosing

    ExecHgCmd g_ThgExec, "commit", ActiveContent.GetFullPath, ActiveContent.GetFullName

    ActiveContent.ReOpenFile
    ActiveContent.JumpToStoredPos
  Else
    ExecHgCmd g_ThgExec, "commit", ActiveContent.GetFullPath, ActiveContent.GetFullName
  End If
End Sub


' :Function: Diff
Sub HgDiff()
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent
  ' Return value of message box
  Dim ansSaveMod As Integer
  ' Message String
  Dim msgAskSaveMod As String

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the file is under version control
  If IsFileUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  If ActiveContent.IsSaved = False Then
  ' Active content is modified but not saved yet.
    ' Test the active content file attributes
    If ActiveContent.IsFileReadOnly = False Then
      If GetDispAskSaveModMsg(True) = gCfgOn Then
        'Save the file
         msgAskSaveMod = _
         AddActiveContentNameToMsg(gmsgAskSaveMod, gmsgFileNameCap, _
                                   True, ActiveContent)
         ansSaveMod = MsgBox(msgAskSaveMod, vbYesNo)
         If ansSaveMod = vbYes Then
           ActiveContent.SaveFile (True)
         End If
      Else
        ActiveContent.SaveFile (False)
      End If
    End If
  End If

  ExecHgCmd g_ThgExec, "vdiff", ActiveContent.GetFullPath, ActiveContent.GetFullName
End Sub


' :Function: Invoke repository browser
Sub HgWorkBench()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod As String
  ' Return value of message box
  Dim ans As Integer
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ExecHgCmd g_ThgwExec, "", ActiveContent.GetFullPath, ""
  
End Sub


' :Function: Log
Sub HgLog()
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

 ' Test the file is under version control
  If IsFileUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ExecHgCmd g_ThgExec, "log", ActiveContent.GetFullPath, ActiveContent.GetFullName
End Sub


' :Function: Add
Sub HgAdd()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod As String
  ' Return value of message box
  Dim ans As Integer
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ans = MsgBox(gmsgAddAskCommit, vbYesNo)
  If ans = vbYes Then
    HgCommit
  Else
    ExecHgCmd g_ThgExec, "add", ActiveContent.GetFullPath, ActiveContent.GetFullName
  End If
End Sub


' :Function: Forget
Sub HgForget()
  ' Message
  Dim msgErrReadOnly As String
  ' Message
  Dim msgAskSaveMod  As String
  ' Return value of message box that confirm to delete the file
  Dim ansAskDelete   As Integer
  ' Return value of message box that confirm to commit the deletion
  Dim ansAskCommit   As Integer
  ' ActiveContent class object
  Dim ActiveContent  As New ActiveContent

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ' Test the folder is under version control
  If IsFolderUnderHgControlWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  ansAskDelete = MsgBox(gmsgDeleteAskDelete, vbYesNo + vbDefaultButton2)
  If ansAskDelete = vbNo Then
    Exit Sub
  End If

  ActiveContent.CloseFile False
  ExecHgCmd g_ThgExec, "forget", ActiveContent.GetFullPath, ActiveContent.GetFullName

End Sub


' :Function: Open explorer and focus on the active content file.
Sub OpenExplorer()
  ' ActiveContent class object
  Dim ActiveContent As New ActiveContent

  ' Exit when no content exist
  If mContents.ContentExist = False Then
    Exit Sub
  End If

  ' Test the active content file status
  If ActiveContentFileExistWithMsg(ActiveContent) = False Then
    Exit Sub
  End If

  CreateObject("WScript.Shell").Run "%SystemRoot%\explorer.exe /e, /select," _
                                    & """" & ActiveContent.GetFullName & """", , True
End Sub


' :Function:     Test whether the active content is saved as a file or not.
'                And this displays error message if the file does't exist.
' :Arguments:    ActCont [i] Active Content to test
' :Return value: True = The file exists., False = No file exists.
Function ActiveContentFileExistWithMsg(ByVal ActCont As ActiveContent) As Boolean
  ' Message
  Dim msgErrFileNotExist As String

  If ActCont.FileExist Then
    ActiveContentFileExistWithMsg = True
  Else
    msgErrFileNotExist = _
    AddActiveContentNameToMsg(gmsgErrActiveContentFileNotExist, _
                              gmsgContentNameCap, False, ActCont)
    MsgBox msgErrFileNotExist
    ActiveContentFileExistWithMsg = False
  End If
End Function


' :Function:     Test whether the file exist in the folder under version control.
'                And this displays error message if the folder isn't under version control.
' :Arguments:    ActCont [i] Active Content to test
' :Return value: True = Under version control, False = Not under version control
Function IsFolderUnderHgControlWithMsg(ByVal ActCont As ActiveContent) As Boolean
  ' Message
  Dim msgErrNotUnderCtrl As String

  If ActCont.IsFolderUnderHgControl Then
    IsFolderUnderHgControlWithMsg = True
  Else
    msgErrNotUnderCtrl = _
    AddActiveContentNameToMsg(gmsgErrFolderNotUnderCtrl, _
                              gmsgFileNameCap, True, ActCont)
    MsgBox msgErrNotUnderCtrl
    IsFolderUnderHgControlWithMsg = False
  End If
End Function


' :Function:     Test whether the file is under subversion control.
' :Arguments:    ActCont [i] Active Content to test
' :Return value: True = Under version control, False = Not under version control
Function IsFileUnderHgControlWithMsg(ByVal ActCont As ActiveContent) As Boolean
  ' Message
  Dim msgErrNotUnderCtrl As String

  If ActCont.IsFileUnderHgControl Then
    IsFileUnderHgControlWithMsg = True
  Else
    msgErrNotUnderCtrl = _
    AddActiveContentNameToMsg(gmsgErrFileNotUnderCtrl, _
                              gmsgFileNameCap, True, ActCont)
    MsgBox msgErrNotUnderCtrl
    IsFileUnderHgControlWithMsg = False
  End If
End Function


' :Function: Add active content file name to the message.
' :Arguments:
' :Return value:
Function AddActiveContentNameToMsg(ByVal msgTrunk As String, _
                                   ByVal FileNameCap As String, _
                                   ByVal bDispFullPath As Boolean, _
                                   ByVal ActCont As ActiveContent) As String
 If bDispFullPath Then
    AddActiveContentNameToMsg = _
    msgTrunk & vbCrLf & vbCrLf & FileNameCap & ActCont.GetFullName
  Else
    AddActiveContentNameToMsg = _
    msgTrunk & vbCrLf & vbCrLf & FileNameCap & ActCont.GetName
  End If
End Function

' :Function: Check to need to close, commit and reopen the file.
' :Return value: True  = Close the file before commit and reopen it
'                False = Not Close the file
Function NeedsCloseAndReopenFileInCommit(ByVal FileFullName As String) As Boolean
  ' Close and reopne file in commiting option
  Dim CiCloseReopneFile As Long

  ' Default return value
  NeedsCloseAndReopenFileInCommit = True

  CiCloseReopneFile = GetCiCloseReopenFile(True)

  Select Case CiCloseReopneFile
    Case gCiNoCloseReopenFile
      NeedsCloseAndReopenFileInCommit = False
    Case gCiCloseReopenFile
      NeedsCloseAndReopenFileInCommit = True
    'Case gCiCloseReopenOnlyNeedsLockFile
    '  If CheckNeedsLockProperty(FileFullName) Then
    '    NeedsCloseAndReopenFileInCommit = True
    '  Else
    '    NeedsCloseAndReopenFileInCommit = False
    '  End If
    Case Else
      MsgBox "Invalid setting in ini file!" & "CiCloseReopenFile : " & CiCloseReopneFile
  End Select
End Function
